package com.friend.chat.page.view.register

import android.os.Bundle
import android.view.View
import android.view.animation.AlphaAnimation
import android.widget.Button
import android.widget.RelativeLayout
import androidx.fragment.app.FragmentActivity
import com.friend.chat.R
import com.friend.chat.page.view.MainActivity
import com.friend.chat.utils.SPUtils
import com.zackratos.ultimatebarx.ultimatebarx.navigationBar
import com.zackratos.ultimatebarx.ultimatebarx.statusBar

class SplashActivity : FragmentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        val userBean = SPUtils.getInstance().getObject("user")
        val view = View.inflate(this, R.layout.activity_splash, null)
        setContentView(view)
        super.onCreate(savedInstanceState)
        statusBar { transparent() }
        navigationBar { transparent() }
        val rvLoginRegister = findViewById<RelativeLayout>(R.id.rv_login_register)
        if (userBean ==null){
            rvLoginRegister.visibility = View.VISIBLE
        }else{
            MainActivity.open(this)
            rvLoginRegister.visibility = View.GONE
            finish()
        }

        val animation = AlphaAnimation(0.3f, 1.0f)
        animation.duration = 1500
        view.animation = animation

        findViewById<Button>(R.id.btn_login).setOnClickListener {
            LoginActivity.open(this)
            finish()
        }

        findViewById<Button>(R.id.btn_register).setOnClickListener {
            RegisterActivity.open(this)
        }


    }
}